

//
//  UIButton+CornerBtn.m
//  GYVVBusiness
//
//  Created by yangfan on 2019/1/18.
//  Copyright © 2019 gongyou04. All rights reserved.
//


#import "UIButton+CornerBtn.h"

@implementation UIButton (CornerBtn)
+ (UIButton *)cornerBtnWithTitle:(NSString *)title fontSize:(CGFloat)fontsize btnType:(CornerBtnType)type{
    return [self cornerBtnWithTitle:title fontSize:fontsize btnType:type height:0 borderWidth:0];
}
+ (UIButton *)cornerBtnWithTitle:(NSString *)title fontSize:(CGFloat)fontsize btnType:(CornerBtnType)type height:(CGFloat)btnHei{
    return [self cornerBtnWithTitle:title fontSize:fontsize btnType:type height:btnHei borderWidth:0];
}
+ (UIButton *)cornerBtnWithTitle:(NSString *)title fontSize:(CGFloat)fontsize btnType:(CornerBtnType)type borderWidth:(CGFloat)borderWidth{
    return [self cornerBtnWithTitle:title fontSize:fontsize btnType:type height:0 borderWidth:borderWidth];
}
+ (UIButton *)cornerBtnWithTitle:(NSString *)title fontSize:(CGFloat)fontsize btnType:(CornerBtnType)type height:(CGFloat)btnHei borderWidth:(CGFloat)borderWidth{
    return [self cornerBtnWithTitle:title fontSize:(kPro(fontsize)) btnType:type height:btnHei borderWidth:borderWidth];
}
+ (UIButton *)cornerBtnWithTitle:(NSString *)title font:(UIFont *)font btnType:(CornerBtnType)type height:(CGFloat)btnHei borderWidth:(CGFloat)borderWidth{
    UIColor *color ;
    UIColor *bgColor;
    switch (type) {
        case CornerBtnTypeBlue:
            color = ssRGBHex(0x007AFF);
            bgColor = ssRGBHexAlpha(0x007AFF,0.1);
            break;
        case CornerBtnTypeGary:
            color = ssRGBHex(0x999999);
            bgColor = ssRGBHexAlpha(0x999999,0.1);
            break;
        case CornerBtnTypeOrange:
            color = ssRGBHex(0xE8541E);
            bgColor = ssRGBHexAlpha(0xE8541E,0.1);
            break;
        case CornerBtnTypeYellow:
            color = ssRGBHex(0xF5A623);
            bgColor = ssRGBHexAlpha(0xF5A623,0.1);
            break;
        default:
            break;
    }
    return [self cornerBtnWithTitle:title font:font titleColor:color bgColor:bgColor height:btnHei borderWidth:borderWidth];
}

+ (UIButton *)cornerBtnWithTitle:(NSString *)title font:(UIFont *)font titleColor:(UIColor *)titleColor bgColor:(UIColor *)bgColor height:(CGFloat)btnHei borderWidth:(CGFloat)borderWidth{
    return [[self alloc]cornerBtnWithTitle:title font:font titleColor:titleColor bgColor:bgColor height:btnHei borderWidth:borderWidth];
}

- (UIButton *)cornerBtnWithTitle:(NSString *)title font:(UIFont *)font titleColor:(UIColor *)titleColor bgColor:(UIColor *)bgColor height:(CGFloat)btnHei borderWidth:(CGFloat)borderWidth{
    UIButton *btn = [[UIButton alloc]init];
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setTitleColor:titleColor forState:UIControlStateNormal];
    btn.titleLabel.font = font;
    btn.backgroundColor = bgColor;
    
    if (borderWidth != 0) {
        btn.layer.borderWidth = borderWidth;
        btn.layer.borderColor = titleColor.CGColor;
    }
    if (btnHei != 0) {
        btn.layer.cornerRadius = btnHei;
    }
    btn.layer.masksToBounds = YES;
    
    return btn;
}
@end
